package train_handler

import (
	"peilian-api/app/global/bind"
	"peilian-api/app/global/errors"
	"peilian-api/app/services/train_service"
	"peilian-api/utils/format"

	"github.com/gin-gonic/gin"
)

// 训练配置中查看该学校的学院-专业
func TrainGetAcademy(ctx *gin.Context) {
	out, err := train_service.TrainGetAcademyUnion(ctx)
	if err != nil {
		format.NewResponseJson(ctx).Err(30001, err.Error())
		return
	}
	format.NewResponseJson(ctx).SuccessObj(out)
}

func TrainConfig(ctx *gin.Context) {
	var ts train_service.CfgReq
	if err := bind.ShouldBinding(ctx, &ts); err != nil {
		format.NewResponseJson(ctx).Err(errors.DatabaseMysqlErrorCode, err.Error())
		return
	}
	out, err := train_service.GetTrainConfig(ctx, ts.Type, ts.Tid, ts.Sid)
	if err != nil {
		format.NewResponseJson(ctx).Err(30002, err.Error())
		return
	}
	format.NewResponseJson(ctx).SuccessObj(out)
}

func GetupConfig(ctx *gin.Context) {
	var gr train_service.GetupReq
	if err := bind.ShouldBinding(ctx, &gr); err != nil {
		format.NewResponseJson(ctx).Err(30001, err.Error())
		return
	}
	out, err := new(train_service.TrainService).GetupConfig(ctx, gr)
	if err != nil {
		format.NewResponseJson(ctx).Err(30002, err.Error())
		return
	}
	format.NewResponseJson(ctx).SuccessObj(out)
}
